#include <stdio.h>
#ifdef _WIN32
#include <intrin.h>
#endif//_WIN32

#ifndef _WIN32
static inline void cpuid(int op, unsigned int *eax, unsigned int *ebx,
    unsigned int *ecx, unsigned int *edx)
{
    __asm__("cpuid"
        : "=a" (*eax),
        "=b" (*ebx),
        "=c" (*ecx),
        "=d" (*edx)
        : "0" (op));
}
static inline void __cpuid(int arr[4], int op)
{
    cpuid(op, (unsigned int *)&arr[0], (unsigned int *)&arr[1], (unsigned int *)&arr[2], (unsigned int *)&arr[3]);
}
#endif//_WIN32

static void inner_get_cpu_serial_number()
{
    int arr[4];

    __cpuid(arr, 1);

    printf("stepping %d\n", arr[0] & 0xF);
    printf("model %d\n", (arr[0] >> 4) & 0xF);
    printf("family %d\n", (arr[0] >> 8) & 0xF);
    printf("processor type %d\n", (arr[0] >> 12) & 0x3);
    printf("extended model %d\n", (arr[0] >> 16) & 0xF);
    printf("extended family %d\n", (arr[0] >> 20) & 0xFF);
    printf("serial number: %02X %02X %02X %02X %02X %02X %02X %02X\n", arr[0] & 0xFF, (arr[0] >> 8) & 0xFF, (arr[0] >> 16) & 0xFF, (arr[0] >> 24) & 0xFF,
        arr[3] & 0xFF, (arr[3] >> 8) & 0xFF, (arr[3] >> 16) & 0xFF, (arr[3] >> 24) & 0xFF);
}

int main(int argc, char **argv)
{
    inner_get_cpu_serial_number();
    return 0;
}
